import { _decorator, Component, KeyCode, Node, UITransform, Vec2 } from 'cc';
import { PlayerState } from './PlayerState';
import { StateDefine } from '../../Config';
const { ccclass, property } = _decorator;

@ccclass('PlayerWallSildeState')
export class PlayerWallSildeState extends PlayerState {
    onEnter() {
        super.onEnter();
    }
    onExit() {
        super.onExit();
        this.animation.node.getComponent(UITransform).anchorPoint = new Vec2(0.5,0.5)//偏移问题
    }
    update(deltaTime: number) {
        super.update(deltaTime);
        if ((!this.player.IsWallDetected())||(this.player.IsGroundDetected())||this.player.input.x != 0 && this.player.facingDir != this.player.input.x){
            this.player.stateMgr.transit(StateDefine.Idle);
        }
        if(this.player.input.y>=0)
            this.player.setVelocity(0,this.rb.linearVelocity.y*(-this.player.input.y+0.8));

        if(this.player.pressedKeys[KeyCode.SPACE]){
            this.player.stateMgr.transit(StateDefine.WallJump);
            return;
        }
    }
    onDestory() { }

    canTransit(to: StateDefine): boolean {
        return true;
    }
}

